package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author iTaotao
 * @version 1.0
 * @Description 订单详情
 * @createTime 2023年08月03日 14:11:00
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/user/order")
public class Ordercontroller {
    private final OrderService orderService;

    /**
     * 催单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/reminder/{id}")
    public Result<?> reminder(@PathVariable Long id) {
        orderService.reminder(id);
        return Result.success();
    }

    /**
     * 提交订单
     *
     * @param ordersSubmitDTO 订单提交dto
     * @return {@link Result}<{@link OrderSubmitVO}>
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);

    }

    /**
     * 再来一单
     *
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/repetition/{id}")
    public Result<?> repetitionAgain(@PathVariable Long id) {
        orderService.repetitionAgain(id);
        return Result.success();
    }

    /**
     * 历史订单
     *
     * @param
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> page(Integer page, Integer pageSize, Integer status) {
        PageResult pageResult = orderService.page(page, pageSize, status);
        return Result.success(pageResult);


    }

    /**
     * 取消订单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/cancel/{id}")
    public Result<?> cancelReminder(@PathVariable Long id) {
        orderService.cancelReminder(id);
        return Result.success();
    }

    /**
     * 根据id查询订单
     *
     * @param id id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> selectOderById(@PathVariable Long id) {
        OrderVO orderVO = orderService.selectOderById(id);
        return Result.success(orderVO);
    }


}
